#ifndef NIXONBOT_CORE_BNCS_PROTOCOL_CHATCOMMAND_H_
#define NIXONBOT_CORE_BNCS_PROTOCOL_CHATCOMMAND_H_

#include <nixonbot/core/bncs/protocol/Message.h>
#include <nixonbot/core/bncs/protocol/MessageFactory.h>

namespace nixonbot {
namespace core {
namespace bncs {
namespace protocol {

struct ChatCommandData : public QSharedData
{
  QByteArray text;
};

class ChatCommand : public Message
{
public:
	static const int id = 0x0e;
	BNCS_MESSAGE_CLIENT_REGISTER(ChatCommand, id);

public:
	QSharedDataPointer<ChatCommandData> d;

public:
	ChatCommand()
	{
		d = new ChatCommandData();
	}
	
	virtual ChatCommand* create()
	{
		return new ChatCommand();
	}
	
	virtual quint32 id()
	{
		return id;
	}

	virtual int size()
	{
	  return (d->text.size() + 1);
	}

protected:
	virtual void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		text = readStringFrom(ds);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	virtual void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		writeStringTo(ds, text);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

}
}
}
}

#endif
